<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>宠物列表</h1>
   <table border="1">
       <tr>
           <th>id</th>
           <th>类型</th>
           <th>数量</th>
           <th>品种</th>
           <th colspan="2">操作</th>
       </tr>
       <tr v-for="p in pet">
           <td>{{p.id}}</td>
           <td>{{p.type}}</td>
           <td>{{p.num}}</td>
           <td>{{p.breed}}</td>
           <td><a :href="'/update.html?id='+p.id">修改</a></td>
           <td><a href="javascript:void(0)" @click="del(p.id)">删除</a></td>
       </tr>
   </table>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
 <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
     <script>
         let v = new Vue({
             el:"body>div",
             data:{
                 pet:[{type:"",num:"",breed:""}]
             },
             methods:{
                 del(id){
                     axios.get("/delete?id="+id).then(function (response) {
                         if(confirm("确定删除")){
                           //刷新页面
                             location.reload();
                         }
                     })
                 }
             },
             created:function () {
                 axios.post("/select").then(function (response) {
                     v.pet=response.data
                 })
             }
         })
     </script>
</body>
</html>